package com.light.common.base;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.List;

/**
 * @Author YHR
 * @Date 2021/2/8 13:59
 * @Version 1.0
 */
@Component
public abstract class BaseServiceImpl<T, M extends BaseMapper> implements BaseService<T> {

    @Autowired
    private M mapper;

    @Override
    public T get(Serializable id) {
        return (T) mapper.selectById(id);
    }

    @Override
    public int save(T t) {
        return mapper.insert(t);
    }

    @Override
    public int update(T t) {
        return mapper.updateById(t);
    }

    @Override
    public int remove(Serializable id) {
        return mapper.deleteById(id);
    }

    @Override
    public int batchRemove(List<Serializable> ids) {
        return mapper.deleteBatchIds(ids);
    }
}
